package com.longge;

public class NumWaterBottles {

    int ans = 0;

    public int numWaterBottles(int numBottles, int numExchange) {
        this.ans = numBottles;
        dfs(numBottles, numExchange);
        return ans;
    }

    public void dfs(int numBottles, int numExchange) {
        if (numBottles < numExchange) return;
        int newNumBottles = numBottles % numExchange + numBottles / numExchange;
        dfs(newNumBottles, numExchange);
        this.ans += numBottles / numExchange;

    }

    public static void main(String[] args) {
        int i = new NumWaterBottles().numWaterBottles(17, 3);
        System.out.println(i);
    }


}
